
#include "command.h"

#include <string.h>


Command::Command()
		: m_cmds(), m_isBg(false), m_size(0) {

	// empty

}


void Command::add(std::vector<std::string> args) {

	if (0 == args.size())
		return;

	char **arr = new char*[args.size() + 1];
	m_cmds.push_back(arr);

	for (std::vector<std::string>::iterator it = args.begin(); it != args.end();
			it++, arr++) {
		*arr = strdup(it->c_str());
	}
	*arr = NULL;

	m_size++;

}


void Command::setBg() {

	m_isBg = true;

}


bool Command::isBg() {

	return m_isBg;

}


int Command::size() {

	return m_size;

}


char* const*& Command::operator[](const int i) {

	return m_cmds[i];

}


Command::~Command() {

	for (int i = 0; i < m_size; i++) {
		for (int j = 0; NULL != m_cmds[i][j]; j++) {
			delete[] m_cmds[i][j];
		}
		delete[] m_cmds[i];
	}

}
